<html>
<head><meta charset="utf-8"><title>Constant::eq skips spans #85208 · t-compiler/wg-mir-opt · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/index.html">t-compiler/wg-mir-opt</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Constant.3A.3Aeq.20skips.20spans.20.2385208.html">Constant::eq skips spans #85208</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="238504162"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Constant%3A%3Aeq%20skips%20spans%20%2385208/near/238504162" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Constant.3A.3Aeq.20skips.20spans.20.2385208.html#238504162">(May 12 2021 at 16:29)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> <span class="user-mention" data-user-id="125294">@Aaron Hill</span> <span aria-label="wave" class="emoji emoji-1f44b" role="img" title="wave">:wave:</span></p>



<a name="238504180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Constant%3A%3Aeq%20skips%20spans%20%2385208/near/238504180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Constant.3A.3Aeq.20skips.20spans.20.2385208.html#238504180">(May 12 2021 at 16:29)</a>:</h4>
<p>maybe is better to discuss this here</p>



<a name="238504289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Constant%3A%3Aeq%20skips%20spans%20%2385208/near/238504289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Constant.3A.3Aeq.20skips.20spans.20.2385208.html#238504289">(May 12 2021 at 16:30)</a>:</h4>
<p>I've just commented on the issue but yeah, it seems to me that this will cause incr. comp. issues</p>



<a name="238504363"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Constant%3A%3Aeq%20skips%20spans%20%2385208/near/238504363" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Constant.3A.3Aeq.20skips.20spans.20.2385208.html#238504363">(May 12 2021 at 16:30)</a>:</h4>
<p>unsure if <span class="user-mention" data-user-id="124288">@oli</span>'s idea of avoiding <code>PartialEq</code> impl would or wouldn't have incr. comp. issues</p>



<a name="238506077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Constant%3A%3Aeq%20skips%20spans%20%2385208/near/238506077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Constant.3A.3Aeq.20skips.20spans.20.2385208.html#238506077">(May 12 2021 at 16:42)</a>:</h4>
<p>Getting rid of the <code>PartialEq</code> impls would fix the violation of the <code>HashStable</code> contract, but you'd still have the incr comp invalidation impl</p>



<a name="238506281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Constant%3A%3Aeq%20skips%20spans%20%2385208/near/238506281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Constant.3A.3Aeq.20skips.20spans.20.2385208.html#238506281">(May 12 2021 at 16:44)</a>:</h4>
<p>One idea would be to add a <code>compare_for_optimization</code> method, remove the <code>PartialEq</code> impl, and keep hashing the span</p>



<a name="238506376"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Constant%3A%3Aeq%20skips%20spans%20%2385208/near/238506376" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Constant.3A.3Aeq.20skips.20spans.20.2385208.html#238506376">(May 12 2021 at 16:44)</a>:</h4>
<p>I think that would also make it easier to understand the optimization passes that need to compare constants</p>



<a name="238510142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Constant%3A%3Aeq%20skips%20spans%20%2385208/near/238510142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Constant.3A.3Aeq.20skips.20spans.20.2385208.html#238510142">(May 12 2021 at 17:10)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125294">Aaron Hill</span> <a href="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/Constant.3A.3Aeq.20skips.20spans.20.2385208/near/238506281">said</a>:</p>
<blockquote>
<p>One idea would be to add a <code>compare_for_optimization</code> method, remove the <code>PartialEq</code> impl, and keep hashing the span</p>
</blockquote>
<p>by remove you meant, leave the derive version of it I guess</p>



<a name="238510225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Constant%3A%3Aeq%20skips%20spans%20%2385208/near/238510225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Constant.3A.3Aeq.20skips.20spans.20.2385208.html#238510225">(May 12 2021 at 17:11)</a>:</h4>
<p>I meant, you're suggesting to add a <code>compare_for_optimization</code> that does equality without spans and use that on the places that we need to optimize</p>



<a name="238510231"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Constant%3A%3Aeq%20skips%20spans%20%2385208/near/238510231" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Constant.3A.3Aeq.20skips.20spans.20.2385208.html#238510231">(May 12 2021 at 17:11)</a>:</h4>
<p>right?</p>



<a name="238514324"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Constant%3A%3Aeq%20skips%20spans%20%2385208/near/238514324" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Constant.3A.3Aeq.20skips.20spans.20.2385208.html#238514324">(May 12 2021 at 17:38)</a>:</h4>
<p>I wonder if we can remove the span entirely without a loss in diagnostics. The custom compare function doesn't help with accidental compares or comparing Operands</p>



<a name="238514751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Constant%3A%3Aeq%20skips%20spans%20%2385208/near/238514751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Constant.3A.3Aeq.20skips.20spans.20.2385208.html#238514751">(May 12 2021 at 17:41)</a>:</h4>
<p>We could add a Location -&gt; span map to Body and fill it in at the beginning.but then optimizations would have to adjust that map, which is no better</p>



<a name="238514957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Constant%3A%3Aeq%20skips%20spans%20%2385208/near/238514957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Constant.3A.3Aeq.20skips.20spans.20.2385208.html#238514957">(May 12 2021 at 17:43)</a>:</h4>
<p>Just removing the span would stop us from being able to point exactly at the use site</p>



<a name="238515253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Constant%3A%3Aeq%20skips%20spans%20%2385208/near/238515253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Constant.3A.3Aeq.20skips.20spans.20.2385208.html#238515253">(May 12 2021 at 17:44)</a>:</h4>
<p>Maybe we should pull the spans into the use sites of the operand? That would be redundant with move/copy operands which have a local whose span we can look up</p>



<a name="238515587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Constant%3A%3Aeq%20skips%20spans%20%2385208/near/238515587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Constant.3A.3Aeq.20skips.20spans.20.2385208.html#238515587">(May 12 2021 at 17:46)</a>:</h4>
<p>Though, since these can have projections, the span isn't really pointing to the place, but to the place's base</p>



<a name="238515688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Constant%3A%3Aeq%20skips%20spans%20%2385208/near/238515688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Constant.3A.3Aeq.20skips.20spans.20.2385208.html#238515688">(May 12 2021 at 17:47)</a>:</h4>
<p>So maybe having a span per operand would even improve diagnostics?</p>



<a name="238657268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Constant%3A%3Aeq%20skips%20spans%20%2385208/near/238657268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Constant.3A.3Aeq.20skips.20spans.20.2385208.html#238657268">(May 13 2021 at 18:02)</a>:</h4>
<p>just force pushed what I currently have, it's very WIP</p>



<a name="238657296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Constant%3A%3Aeq%20skips%20spans%20%2385208/near/238657296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Constant.3A.3Aeq.20skips.20spans.20.2385208.html#238657296">(May 13 2021 at 18:02)</a>:</h4>
<p>it compiles and I did a quick review, left some comments with things that I quickly saw</p>



<a name="238657396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Constant%3A%3Aeq%20skips%20spans%20%2385208/near/238657396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Constant.3A.3Aeq.20skips.20spans.20.2385208.html#238657396">(May 13 2021 at 18:03)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> if you can take a look and check if this is more or less what you were imagining, would be great</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>